﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AppToolkit.WPF.Services.UserMessageHandling;
using UnitTestUtils.UI;
using AppToolkit.WPF.Services.UserMessageHandling.UI;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;

namespace AppToolkit.WPF.Tests.Services.UserMessageHandling.UI
{
    [TestFixture]
    public class MessageViewTests
    {
        [TearDown]
        public void Dispose()
        {
            UnitTestUtils.UI.UITestHelper.CleanupDispatcher();
        }

        [Test, RequiresSTA]
        public void Check_DataBinding_on_MessageView()
        {
            TestWindow wnd = new TestWindow();

            MessageService svc = new MessageService();

            var view = new MessageView();
            var host = UIHost.Create(view);
            
            view.DataContext = svc;

            host.Show();

            Message msg = new Message()
            {
                Subject = "The subject to show!",
                Details = "The details that I do not want to leave unmentionend.",
                Type = MessageType.Critical,
            };
            svc.ShowMessage(msg);

            host.Window.Dispatcher.Flush();

            TextBox txt = (TextBox)LogicalTreeHelper.FindLogicalNode(view, "txtMessage");
            Assert.AreEqual(msg.Subject, txt.Text);
            
            host.WaitForClose();
        }


        [Test,RequiresSTA]
        public void DesiredResult()
        {
            TestWindow wnd = new TestWindow();

            MessageService svc = new MessageService();
            wnd._messageViewHost.Visualizer = svc;
            wnd.DataContext = svc;

            wnd.ShowDialog();
        }

    }
}
